#pragma once

using namespace System;
using namespace NUnit::Framework;
using namespace LatoolNet;

namespace LatoolNetTest {

	[TestFixture]
	public ref class ComplexHermitianTridiagonalMatrixTest {
	public:

		[Test]
		void TestFactorizeAndSolve() {
			
			int rownum = 4;
			int colnum = 4;

			ComplexMatrix ^a = gcnew ComplexMatrix(rownum, colnum, MatrixType::ComplexHermitianTridiagonal);
			
			a[0, 0] = Complex(16.0, 0.0);
			a[0, 1] = Complex(16.0, -16.0);

			a[1, 1] = Complex(41.0, 0.0);
			a[1, 2] = Complex(18.0, 9.0);

			a[2, 2] = Complex(46.0, 0.0);
			a[2, 3] = Complex(1.0, 4.0);

			a[3, 3] = Complex(21.0, 0.0);

			ComplexMatrix ^ b = gcnew ComplexMatrix(rownum, 1);

			b[0, 0] = Complex(64.0, 16.0);
			b[1, 0] = Complex(93.0, 62.0);
			b[2, 0] = Complex(78.0, -80.0);
			b[3, 0] = Complex(14.0, -27.0);

			//LUFactorization::Factorize(a);
			LinearEquation::Factorize(a);

			//LUFactorization::Solve(a, b);
			LinearEquation::Solve(a,b);

			Console::WriteLine(b->ToString());

			Assert::AreEqual(2.0, b[0, 0].Real, 1e-10, "Test: Solve.");
			Assert::AreEqual(1.0, b[0, 0].Imag, 1e-10, "Test: Solve.");
			Assert::AreEqual(1.0, b[1, 0].Real, 1e-10, "Test: Solve.");
			Assert::AreEqual(1.0, b[1, 0].Imag, 1e-10, "Test: Solve.");
			Assert::AreEqual(1.0, b[2, 0].Real, 1e-10, "Test: Solve.");
			Assert::AreEqual(-2.0, b[2, 0].Imag, 1e-10, "Test: Solve.");
			Assert::AreEqual(1.0, b[3, 0].Real, 1e-10, "Test: Solve.");
			Assert::AreEqual(-1.0, b[3, 0].Imag, 1e-10, "Test: Solve.");

		};

		//[Test]
		//void TestSolve() {
		//	
		//	int rownum = 4;
		//	int colnum = 4;

		//	ComplexMatrix ^a = gcnew ComplexMatrix(rownum, colnum, MatrixType::ComplexHermitianTridiagonal);
		//	
		//	a[0, 0] = Complex(16.0, 0.0);
		//	a[0, 1] = Complex(16.0, -16.0);

		//	a[1, 1] = Complex(41.0, 0.0);
		//	a[1, 2] = Complex(18.0, 9.0);

		//	a[2, 2] = Complex(46.0, 0.0);
		//	a[2, 3] = Complex(1.0, 4.0);

		//	a[3, 3] = Complex(21.0, 0.0);

		//	ComplexMatrix ^ b = gcnew ComplexMatrix(rownum, 1);

		//	b[0, 0] = Complex(64.0, 16.0);
		//	b[1, 0] = Complex(93.0, 62.0);
		//	b[2, 0] = Complex(78.0, -80.0);
		//	b[3, 0] = Complex(14.0, -27.0);

		//	try {
		//		LUFactorization::Solve(a, b);
		//	} catch (Exception^ ex) {
		//		Assert::IsInstanceOfType(, ex);
		//	}


		//};
	

	};
}
